package com.aliyun.heiyu.powermaster.server.rotary.task;

import com.aliyun.heiyu.powermaster.server.rotary.service.AirService;
import com.aliyun.heiyu.powermaster.server.rotary.service.impl.AirServiceImpl;
import com.aliyun.heiyu.powermaster.server.util.ZkClientUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Calendar;
import java.util.Date;

/**
 * @Description 获取空调数据的任务
 * @Author shun.zhang
 * @Date 2020/1/8 10:59
 **/
public class GetAirDataTask implements Job {
    private static Logger logger = LoggerFactory.getLogger(GetAirDataTask.class);
    public static Date airDate;
    private AirService airService = new AirServiceImpl();

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        if(ZkClientUtil.checkLeader()) {
            airDate = Calendar.getInstance().getTime();
            logger.info("{}:执行获取空调数据的任务", new Date());
            if (!AirServiceImpl.isRatoryStatus()) {
                logger.info("动环状态处于关闭状态");
                return;
            }
            airService.saveDataByAir();
        }
    }
}
